﻿#region Usings

using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.Surface.Presentation.Controls;

#endregion

namespace ScrumTable.UI.View.WinTouch.CustomControl
{
    /// <summary>
    /// DigitBox
    /// </summary>
    public class DigitBox : SurfaceTextBox
    {

        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------
        private Thickness _oldThickness = new Thickness(0);
        private Brush _oldBorderBrush;
        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------
     
        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------
        public DigitBox()
        {
            Margin = new Thickness(3, 0, 3, 0);
            MaxLength = 8;
        }
        #endregion




        #region Methods
        
        protected override void OnLostFocus(System.Windows.RoutedEventArgs e)
        {
            double ret;

            if (_oldBorderBrush == null) { _oldBorderBrush = BorderBrush; _oldThickness = BorderThickness; }

            if (string.IsNullOrEmpty(Text) || double.TryParse(Text, NumberStyles.Float, CultureInfo.InvariantCulture, out ret)) 
            { 
                BorderBrush = _oldBorderBrush ?? BorderBrush;
                BorderThickness = _oldThickness;
            }
            else
            {
                BorderBrush = Brushes.Red;
                BorderThickness = new Thickness(2);
                
            }
            base.OnLostFocus(e);
        }

        #endregion
        #region Events

        #endregion
    }
}
